package view.servlet.ajax;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Pattern;

/**
 * @author wq3stone
 */

@WebServlet("/checkPassword1Register")
public class CheckPassword1Register extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String rex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$";
        String pwd1 = req.getParameter("password1");
        PrintWriter out = resp.getWriter();
        if (pwd1.length()<8) {
            out.print("<font color=red>密码至少为8位</font>");
        }else if (!Pattern.matches(rex,pwd1)) {
            out.print("<font color=red>密码由大小写字母和数字组成</font>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
